package com.stars.common;

import java.io.*;

/**
 * 文件生成工具 @author xiaowei on 2018/7/24.
 */
public class FileGenerater {
    public void createFile(String name, String type, String path, String[] codes) {

        File f = new File(path);

        if (!f.exists()) {
            // 创建目录
            f.mkdirs();
        }

        // 文件名及类型
        String fileName = name + "." + type;

        File file = new File(path, fileName);
        try (OutputStream out = new FileOutputStream(file);
             BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, "utf-8"));) {

            for (String code : codes) {
                bw.write(code);
                bw.write("\n");
            }

            bw.flush();
            bw.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        /*if (!file.exists()) {



        }*/

    }

    public void createFiles(String name, String path, String[] filesName) {
        /*
		 * String fileName; for(String fname:filesName){ fileName = name +
		 * fname; createFile(fileName,path); }
		 */
    }

    public static void main(String[] args) {
        FileGenerater fileGenerater = new FileGenerater();
        String[] filesName = {"Form", "Grid", "SearchForm", "Toolbar", "ViewModel", "Window", "WindowAdd",
                "WindowEdit"};
        // 所创建文件的路径
        String path = "C:\\LOSS\\tpm-web\\src\\main\\webapp\\script\\js\\app\\view\\loss\\subject\\ctq3";
        // fileGenerater.createFiles("SubjectApply",path,filesName);
        // fileGenerater.createFile("xiaowei",path);
    }

}
